//
//  ChoosePeopleNumViewController.m
//  CDlife
//
//  Created by 戴伟 on 2017/11/25.
//  Copyright © 2017年 戴伟. All rights reserved.
//

#import "ChooseDateViewController.h"
#import "NSDate+Helper.h"

@interface ChooseDateViewController ()


@property (weak, nonatomic) IBOutlet UIView *containerView;
@property (nonatomic, strong) UIDatePicker *datePicker;


@end

@implementation ChooseDateViewController


- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor colorWithHexString:@"#000000" andAlpha:0.0];

    [self.containerView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(240);
    }];


    _datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 45, DEVICE_SCREEN_WIDTH, 180)];
    _datePicker.datePickerMode = _datePickerMode;
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];//设置为中文
    _datePicker.locale = locale;
    [_datePicker setDate:[NSDate date]];
    [self.containerView addSubview:_datePicker];
}


-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
    [self.containerView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(0);
    }];
    
    [UIView animateWithDuration:0.4 animations:^{
        self.view.backgroundColor = [UIColor colorWithHexString:@"#000000" andAlpha:0.4];
        [self.view layoutIfNeeded];
    }];
}
- (IBAction)confirm:(id)sender {
    NSDate *date = _datePicker.date;
//    NSString *dateStr = [date stringWithFormat:@"yyyy-MM-dd"];
    if (self.chooseDateComplete) {
        self.chooseDateComplete(date);
    }
    [self cancel:nil];
}

- (IBAction)cancel:(id)sender {
    [self.containerView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(240);
    }];
    [UIView animateWithDuration:0.4 animations:^{
        self.view.backgroundColor = [UIColor clearColor];
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:nil];
    }];
}


@end
